<pre class="code">
<span class="srcline"><span class="lineno"><a href="1,1" id="srcline1"> 1</a></span><span class="line"><span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,2" id="srcline2"> 2</a></span><span class="line"><span class="comment">% RPI-MATLAB-Simulator</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,3" id="srcline3"> 3</a></span><span class="line"><span class="comment">% http://code.google.com/p/rpi-matlab-simulator/</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,4" id="srcline4"> 4</a></span><span class="line"><span class="comment">%</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,5" id="srcline5"> 5</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="1,6" id="srcline6"> 6</a></span><span class="line"><span class="keyword">function</span> <span class="var type1" id="S2T6U3">sim</span> = sphere_on_sphere()</span></span>
<span class="srcline"><span class="lineno"><a href="1,7" id="srcline7"> 7</a></span><span class="line"> <span class="comment">%#codegen</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,8" id="srcline8"> 8</a></span><span class="line">    <span class="comment">% Initialize simulator</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,9" id="srcline9"> 9</a></span><span class="line">    <span class="mxinfo" id="T6:U2"><span class="var type1" id="S2T6U8">sim</span> = <span class="mxinfo" id="T6:U4"><span class="fcn" id="F12N5:B10">Simulator</span>(<span class="mxinfo" id="T1:U5">0.01</span>)</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="1,10" id="srcline10">10</a></span><span class="line">    <span class="comment">%sim.drawContacts = true;</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,11" id="srcline11">11</a></span><span class="line">    <span class="mxinfo" id="T1:U6"><span class="mxinfo" id="T1:U7"><span class="var type1" id="S2T6U15">sim</span>.MAX_STEP</span> = <span class="mxinfo" id="T1:U9">500</span></span>;     </span></span>
<span class="srcline"><span class="lineno"><a href="1,12" id="srcline12">12</a></span><span class="line">    <span class="mxinfo" id="T4:U10"><span class="mxinfo" id="T4:U11"><span class="var type1" id="S2T6U21">sim</span>.draw</span> = <span class="mxinfo" id="T4:U13">false</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="1,13" id="srcline13">13</a></span><span class="line">    <span class="comment">%sim.H_dynamics = @LCPdynamics; </span></span></span>
<span class="srcline"><span class="lineno"><a href="1,14" id="srcline14">14</a></span><span class="line">    <span class="comment">%sim.H_solver = @Lemke;</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,15" id="srcline15">15</a></span><span class="line">    <span class="comment">%sim.H_dynamics = @mLCPdynamics; </span></span></span>
<span class="srcline"><span class="lineno"><a href="1,16" id="srcline16">16</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="1,17" id="srcline17">17</a></span><span class="line">    <span class="comment">% A sphere</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,18" id="srcline18">18</a></span><span class="line">    <span class="mxinfo" id="T32:U14"><span class="var type1" id="S5T32U27">s1</span> = <span class="mxinfo" id="T32:U16"><span class="fcn" id="F40N4:B29">Body_sphere</span>(1,2)</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="1,19" id="srcline19">19</a></span><span class="line">        <span class="mxinfo" id="T1:U17"><span class="mxinfo" id="T1:U18"><span class="var type1" id="S5T32U35">s1</span>.mass</span> = <span class="mxinfo" id="T1:U20">20</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="1,20" id="srcline20">20</a></span><span class="line">        <span class="mxinfo" id="T7:U21"><span class="mxinfo" id="T7:U22"><span class="var type1" id="S5T32U41">s1</span>.u</span> = <span class="mxinfo" id="T7:U24">[<span class="mxinfo" id="T1:U25">0</span>; <span class="mxinfo" id="T1:U26">0</span>; <span class="mxinfo" id="T1:U27">-<span class="mxinfo" id="T1:U28">1</span></span>]</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="1,21" id="srcline21">21</a></span><span class="line">        <span class="mxinfo" id="T22:U29"><span class="mxinfo" id="T22:U30"><span class="var type1" id="S5T32U54">s1</span>.color</span> = <span class="mxinfo" id="T22:U32">[<span class="mxinfo" id="T1:U33">.7</span> <span class="mxinfo" id="T1:U34">.7</span> <span class="mxinfo" id="T1:U35">.7</span>]</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="1,22" id="srcline22">22</a></span><span class="line">        <span class="mxinfo" id="T1:U36"><span class="mxinfo" id="T1:U37"><span class="var type1" id="S5T32U64">s1</span>.num_sphere_verts</span> = <span class="mxinfo" id="T1:U39">25</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="1,23" id="srcline23">23</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="1,24" id="srcline24">24</a></span><span class="line">    <span class="mxinfo" id="T32:U40"><span class="var type1" id="S7T32U69">s2</span> = <span class="mxinfo" id="T32:U42"><span class="fcn" id="F41N4:B71">Body_sphere</span>(0.25,0.25)</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="1,25" id="srcline25">25</a></span><span class="line">        <span class="mxinfo" id="T7:U43"><span class="mxinfo" id="T7:U44"><span class="var type1" id="S7T32U77">s2</span>.u</span> = <span class="mxinfo" id="T7:U46">[<span class="mxinfo" id="T1:U47">-<span class="mxinfo" id="T1:U48">0.05</span></span>; <span class="mxinfo" id="T1:U49">0.05</span>; <span class="mxinfo" id="T1:U50">1.25</span>]</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="1,26" id="srcline26">26</a></span><span class="line">        <span class="mxinfo" id="T1:U51"><span class="mxinfo" id="T1:U52"><span class="var type1" id="S7T32U90">s2</span>.num_sphere_verts</span> = <span class="mxinfo" id="T1:U54">15</span></span>;</span></span>
<span class="srcline"><span class="lineno"><a href="1,27" id="srcline27">27</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="1,28" id="srcline28">28</a></span><span class="line">    <span class="mxinfo" id="T34:U55"><span class="var type1" id="S8T34U95">P</span> = <span class="mxinfo" id="T34:U57"><span class="fcn" id="F64N3:B97">Body_plane</span>([0;0;-3],[0;0;1])</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="1,29" id="srcline29">29</a></span><span class="line">        </span></span>
<span class="srcline"><span class="lineno"><a href="1,30" id="srcline30">30</a></span><span class="line">    <span class="mxinfo" id="T6:U58"><span class="var type1" id="S2T6U115">sim</span> = <span class="mxinfo" id="T6:U60"><span class="fcn" id="F94N12:B117">sim_addBody</span>(<span class="var type1" id="S2T6U118">sim</span>, <span class="mxinfo" id="T36:U62">[<span class="var type1" id="S8T34U121">P</span> <span class="var type1" id="S5T32U122">s1</span> <span class="var type1" id="S7T32U123">s2</span>]</span>)</span></span>;    <span class="comment">% Add bodies to simulator</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,31" id="srcline31">31</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="1,32" id="srcline32">32</a></span><span class="line">    <span class="comment">% Run the simulator!</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,33" id="srcline33">33</a></span><span class="line">    <span class="mxinfo" id="T6:U66"><span class="var type1" id="S2T6U126">sim</span> = <span class="mxinfo" id="T6:U68"><span class="fcn" id="F103N14:B128">sim_run</span>(<span class="var type1" id="S2T6U129">sim</span>)</span></span>; </span></span>
<span class="srcline"><span class="lineno"><a href="1,34" id="srcline34">34</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="1,35" id="srcline35">35</a></span><span class="line"><span class="keyword">end</span></span></span>
<span class="srcline"><span class="lineno"><a href="1,36" id="srcline36">36</a></span><span class="line"></span></span>
<span class="srcline"><span class="lineno"><a href="1,37" id="srcline37">37</a></span><span class="line"></span></span>
</pre>
